package eqsolver;

public class Solver implements ISolver{
	
	IEquation equation;
	float[] solution;
	
	public Solver(IEquation equation) {
		this.equation = equation;
	}
	
	public void solve() {
	System.out.println("dal solver "+equation.getParam()[0]+" "+equation.getParam()[1]+" "+equation.getNumberParam());
		switch (equation.getNumberParam()) {
		case 1:
			
			//la responsabilità adesso è del modello se volessi implementare solver1 e 2 (algoritmi diversi)
			//dovrei togliere questa responsabilità ai modelli e darla ai solver
				IEquation linearequ1 = new ModelLinearEquation();
				linearequ1.setEquation(equation.getNumberParam(), equation.getParam());
				solution = linearequ1.getSol();
				System.out.println(solution[0]);
				//solution = new Solver1(equation).getSolution();
				break;
		case 2:
		
		//la responsabilità adesso è del modello se volessi implementare solver1 e 2 (algoritmi diversi)
		//dovrei togliere questa responsabilità ai modelli e darla ai solver
			IEquation linearequ = new ModelLinearEquation();
			linearequ.setEquation(equation.getNumberParam(), equation.getParam());
			solution = linearequ.getSol();
			System.out.println(solution[0]);
			//solution = new Solver1(equation).getSolution();
			break;
		case 3:
			IEquation quadraticeq = new ModelQuadraticEquation();
			quadraticeq.setEquation(equation.getNumberParam(), equation.getParam());
			solution = quadraticeq.getSol();
			//solution = new Solver2(equation).getSolution();
			break;
		case 4:
			//new Solver3(equation);
			break;
		case 5:
			//new Solver4(equation);
			break;
		default:
		
		System.out.println("nessun solver istanziato");
			//eccezione
			break;
		}
		
	}
	
	public float[] getSolution() {
		return solution;
	}
}
